/**
 *
 * The MIT License
 *
 * Copyright (c) 2009 Noritaka Horio all rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * @author Noritaka Horio <holy.shared.design@gmail.com>
 * @see http://mootools.net - Javascript framework MooTools -
 * @see http://iddy.jp/ - Profile making service for blogger -
 * @license MIT License http://www.opensource.org/licenses/mit-license.php
 *
 */

var Iddy;
if (!Iddy) Iddy = {};

Iddy.Book  = new Class({

	Extends: Iddy.Strategy,

	options: {
		"assets": {
			"title": "images/ttl_profile.gif",
			"load": "images/img_loading.gif",
			"close": "images/btn_close_off.gif",
			"detail": "images/btn_detail_off.gif"
		}
	},

	initialize: function(options) {
		this.parent(options);
	},

	request: function() {
		this.container.addClass("request");
		this.container.set("html", "");

		var loading = "";
		 loading += "<p class='loading'><img src='" + this.options.assets.load + " ' />loading...</p>";
		 loading += "<p class='poweredBy'>Powered by <a title='iddyへ' href='" + this.iddyURL + "'>iddy.jp</a></p>";

		this.container.set("html", loading);

		var size = this.container.getSize();
		this.container.get("morph").start({
			"margin-top": [-(size.y / 2) + 50, -(size.y / 2)],
			"opacity": [0, 1]
		});
	},

	success: function(responseJSON, responseText) {
		this.container.removeClass("request");
		this.container.addClass("loaded");
		this.container.set("html", "");

		var user	= responseJSON.users[0];

		var header  = "";
		header += "<div class='header'>";
		header += "    <p class='title'><strong><img src='" + this.options.assets.title + "' alt='My Profile' /></strong></p>";
		header += "</div>";

		var content = "";
		content += "<div class='content'>";
		content += "    <div class='profileOutline'>";
		content += "        	<p class='photo'><a title='"+ user.accountname + "' href='"+ user.profileurl + "'><img src='" +user.imageurl + "' alt='' /></a></p>";
		content += "	        <p class='name'><strong>" + user.accountname + "</strong></p>";
		content += "	        <p>" + user.profile + "</p>";
		content += "	        <p><a href='mailto:" + user.mail + "'>" + user.mail + "</a></p>";
		content += "    </div>";
		content += "    <dl class='profileDetail'>";
		content += "	        <dt>好きな映画</dt><dd>"+ user.favoritemovie + "</dd>";
		content += "	        <dt>好きな食べ物</dt><dd>"+ user.favoritefood + "</dd>";
		content += "	        <dt>好きな音楽</dt><dd>"+ user.favoritemusic + "</dd>";
		content += "	        <dt>趣味</dt><dd>"+ user.hobby + "</dd>";
		content += "	        <dt>パーソナルタグ</dt><dd>"+ user.personaltag + "</dd>";
		content += "    </dl>";
		content += "</div>";

		var footer = "";
		footer += "<div class='footer'>";
		footer += "	<p class='control'>";
		footer += "		<a class='detail' title='詳細を表示する' href='" + user.profileurl + "'><img src='" + this.options.assets.detail + "' alt='詳細を表示する' /></a>";
		footer += "		<a class='close' title='閉じる' href='#'><img src='" + this.options.assets.close + "' alt='閉じる' /></a>";
		footer += "	</p>";
		footer += "	<p class='poweredBy'>Powered by <a title='iddyへ' href='" + this.iddyURL + "'>iddy.jp</a></p>";
		footer += "</div>";

		this.container.set("html", header + content + footer);

		var containerSize = this.container.getSize();
		this.container.setStyles({
			"visibility": "visible",
			"opacity": 0,
			"height": containerSize.y,
			"margin-top": -Math.round(containerSize.y / 2) - 50,
			"width": containerSize.x,
			"margin-left": -Math.round(containerSize.x / 2)
		});

		this.container.get("morph").start({
			"margin-top": [
				-Math.round(containerSize.y / 2) - 50,
				-Math.round(containerSize.y / 2)
			],
			"opacity": [0, 1]
		});
	}
});